<?php
/**
* 插入排序
*/

function insertionSort($numArray) {
    $len = count($numArray);

    for($i = 1; $i < $len; $i++) {
        $key = $numArray[$i];
        for($j = $i-1; $j >=0; $j--) {
            if ( $numArray[$j] > $key ) {
                $numArray[$j+1] = $numArray[$j];
            } else {
                break;
            }
        }
        $numArray[$j+1] = $key;
    }
    return $numArray;

}


$arr = [1,3,5,7,2,3,4,6,8];

print_r(insertionSort($arr));


?>
